package com.mjh.controller;

import com.github.pagehelper.PageInfo;
import com.mjh.bean.Tran;
import com.mjh.model.R;
import com.mjh.service.CustomerService;
import com.mjh.service.TranService;
import com.mjh.vo.CustomerVo;
import com.mjh.vo.TranVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**交易信息
 * @author mjh
 * @create 2021-06-09 21:06
 */
@RestController
@RequestMapping("/api/tran")
public class TranController {
    @Autowired
    private TranService tranService;

    /**
     * 分页查询交易信息列表
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/page")
    public R<PageInfo<CustomerVo>> loadTranPage(@RequestParam Integer current,
                                                    @RequestParam(required = false, defaultValue = "10") Integer size) {

        PageInfo<CustomerVo> pageInfo = tranService.queryTranListByPage(current, size);
        return R.OK(pageInfo);
    }
    /**
     * 新增交易信息
     * @param tran
     * @return
     */
    @PostMapping
    public R<String> saveTran(@RequestBody Tran tran) {
        Boolean flag = tranService.saveTran(tran);
        return R.HANDLER(flag);
    }
    /**
     * 根据id删除交易信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R<String> removeTranById(@PathVariable Integer id) {
        Boolean flag = tranService.removeTranById(id);
        return R.HANDLER(flag);
    }
    @GetMapping("{id}")
    public R<Tran> loadTranInfoById(@PathVariable Integer id) {
        Tran tran = tranService.queryTranInfoById(id);
        return R.OK(tran);
    }
    @PutMapping
    public R<String> modifyTran(@RequestBody Tran tran) {
        Boolean flag = tranService.modifyTran(tran);
        return R.HANDLER(flag);
    }


}
